import { BaseProcessor } from './baseProcessor.js'
import xlsx from 'xlsx'

export class ExcelProcessor extends BaseProcessor {
  async process(filePath) {
    const workbook = xlsx.readFile(filePath)
    const texts = []

    for (const sheetName of workbook.SheetNames) {
      const sheet = workbook.Sheets[sheetName]
      const text = xlsx.utils.sheet_to_txt(sheet, { raw: false })
      if (text.trim()) {
        texts.push(`[${sheetName}]\n${text}`)
      }
    }

    return this.normalizeWhitespace(texts.join('\n\n'))
  }
} 